<template>
  <div class="layout-wrapper">
    <!-- Header -->
    <el-header class="header">
      <div class="header-content">
        <img src="@/assets/imgs/logo.png" class="logo">
        <div class="title">药店管理系统员工中心</div>
        <el-dropdown class="user-dropdown" placement="bottom">
          <div class="user-info">
            <img :src="imageUrl || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" alt="User Avatar" class="avatar"/>
            <span class="user-name">员工：{{ userName }}</span>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>

    <!-- Main layout -->
    <div class="main-content">
      <!-- Sidebar -->
      <el-aside class="sidebar">
        <el-menu :default-active="router.currentRoute.value.path" :default-openeds="['/SELLER/index', '1']" router class="menu">
          <el-menu-item index="/SELLER/index">
            <el-icon><HomeFilled /></el-icon>
            <span>员工首页</span>
          </el-menu-item>

          <!-- Sales Management -->
          <el-sub-menu index="1">
            <template #title>
              <el-icon><Management /></el-icon>
              <span>销售管理</span>
            </template>
            <el-menu-item index="/SELLER/order">
              <el-icon><DocumentCopy /></el-icon>
              <span>生成订单</span>
            </el-menu-item>
            <el-menu-item index="/SELLER/manageOrder">
              <el-icon><DocumentCopy /></el-icon>
              <span>销售订单管理</span>
            </el-menu-item>
          </el-sub-menu>
          <el-menu-item index="/SELLER/countStock">
            <el-icon><Edit /></el-icon>
            <span>库存盘点</span>
          </el-menu-item>
          <!-- Damage Report -->
          <el-menu-item index="/SELLER/damageReport">
            <el-icon><Warning/></el-icon>
            <span>货物报损</span>
          </el-menu-item>

          <!-- Personal Info -->
          <el-menu-item index="/SELLER/persional">
            <el-icon><User /></el-icon>
            <span>个人信息管理</span>
          </el-menu-item>


          <!-- Logout -->
          <el-menu-item @click="logout">
            <el-icon><SwitchButton /></el-icon>
            <span>退出登录</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!-- Main Content -->
      <el-main class="main">
        <router-view />
      </el-main>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue';
import router from "@/router";
import { ElMessage } from "element-plus";
import { expiration, setToExpireLocalStroage } from "@/utils/LocalStroageUtil";

const user = JSON.parse(localStorage.getItem('system-user') || '{}');
const userName = user.name;
const imageUrl = user.avatar;
const logout = () => {
  ElMessage.success('退出成功');
  localStorage.removeItem('system-user');
  router.push('/');
}

// 设置过期
setToExpireLocalStroage(expiration);
</script>

<style scoped>
.layout-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #f5f7fa;
}

.header {
  height: 60px;
  background-color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid #e4e7ed;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  align-items: center;
  width: 100%;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

.title {
  font-weight: 600;
  font-size: 20px;
  margin-left: 12px;
  color: #3b97f8;
}

.user-dropdown {
  margin-left: auto;
}

.user-dropdown .user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.user-dropdown .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin-right: 8px;
}

.user-dropdown .user-name {
  font-size: 14px;
  color: #606266;
}

.main-content {
  display: flex;
  flex: 1;
  margin-top: 60px;
}

.sidebar {
  width: 240px;
  border-right: 1px solid #e4e7ed;
  min-height: calc(100vh - 60px);
  position: fixed;
  top: 60px;
  left: 0;
  background: #ffffff;
  z-index: 999;
  overflow-y: auto;
  box-shadow: 2px 0 8px 0 rgba(0, 0, 0, 0.1);
  transition: width 0.3s ease;
}

.sidebar:hover {
  width: 250px;
}

.main {
  flex: 1;
  margin-left: 240px;
  padding: 24px;
  background-color: #f5f7fa;
  overflow-y: auto;
}

.el-menu {
  border-right: none;
  padding-top: 16px;
}

.el-menu-item {
  height: 48px;
  line-height: 48px;
  font-size: 14px;
  color: #606266;
  font-weight: 500;
  padding-left: 24px;
  border-radius: 8px;
  transition: all 0.3s ease;
  margin: 4px 0;
}

.el-menu-item.is-active {
  background-color: #409eff;
  color: #ffffff;
  box-shadow: inset 4px 0 0 0 #ffffff;
}

.el-menu-item:hover {
  background-color: #ecf5ff;
  color: #409eff;
}

.el-sub-menu {
  margin-left: 16px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.el-sub-menu__title {
  font-size: 14px;
  color: #606266;
  font-weight: 500;
  padding-left: 24px;
  transition: all 0.3s ease;
}

.el-sub-menu__title:hover {
  color: #409eff;
}

.el-menu-item.is-active .el-icon,
.el-menu-item:hover .el-icon {
  color: #ffffff;
}

.el-icon {
  font-size: 18px;
  margin-right: 12px;
  transition: color 0.3s ease;
}

.el-menu-item.is-active .el-icon,
.el-menu-item:hover .el-icon {
  color: #ffffff;
}

.el-menu-item.is-active {
  background-color: #409eff !important;
  color: #ffffff;
  box-shadow: inset 4px 0 0 0 #ffffff;
}

.el-sub-menu__title {
  padding: 12px 24px;
}

:deep(th) {
  color: #303133;
  font-weight: 600;
}
</style>